package com.zz.common.tunnel;

import io.netty.channel.Channel;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class TunnelCache {

    private final static Map<Channel, Long> heartbeatCaches = new ConcurrentHashMap<>();

    public static boolean isReplyHeartbeat(Channel channel, long serialNumber) {
        if (!heartbeatCaches.containsKey(channel)) {
            return false;
        }
        if (heartbeatCaches.get(channel) == serialNumber) {
            heartbeatCaches.remove(channel);
            return true;
        }
        return false;
    }

    public static void remoteHeartbeatCachesByChannel(Channel channel) {
        heartbeatCaches.remove(channel);
    }

    public static void setHeartbeatCaches(Channel channel, long serialNumber) {
        heartbeatCaches.put(channel, serialNumber);
    }
}
